﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SharpSoft.WPF.Controls
{
    /// <summary>
    /// 可以用多个图片表示按钮状态
    /// </summary>
    public class ImageStateButton : TouchButton
    {
        static ImageStateButton()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageStateButton), new FrameworkPropertyMetadata(typeof(ImageStateButton)));
        }
        public ImageStateButton()
        { 
        }

        [Category("多状态")]
        [Description("常规状态下显示的图片")]
        public ImageSource ImageNormal
        {
            get { return (ImageSource)GetValue(ImageNormalProperty); }
            set { SetValue(ImageNormalProperty, value); }
        }

        public static readonly DependencyProperty ImageNormalProperty =
            DependencyProperty.Register("ImageNormal", typeof(ImageSource), typeof(ImageStateButton), new PropertyMetadata(null, new PropertyChangedCallback((dobj, e) =>
            {
                if (dobj is ImageStateButton btn)
                {
                    if (btn.ImageDisabled == null)
                    {
                        btn.ImageDisabled = btn.ImageNormal;
                    }
                    if (btn.ImagePressed == null)
                    {
                        btn.ImagePressed = btn.ImageNormal;
                    }
                }
            })));



        [Category("多状态")]
        [Description("按钮按下时显示的图片")]
        public ImageSource ImagePressed
        {
            get { return (ImageSource)GetValue(ImagePressedProperty); }
            set { SetValue(ImagePressedProperty, value); }
        }

        public static readonly DependencyProperty ImagePressedProperty =
            DependencyProperty.Register("ImagePressed", typeof(ImageSource), typeof(ImageStateButton), new PropertyMetadata(null));



        [Category("多状态")]
        [Description("按钮禁用时显示的图片")]
        public ImageSource ImageDisabled
        {
            get { return (ImageSource)GetValue(ImageDisabledProperty); }
            set { SetValue(ImageDisabledProperty, value); }
        }

        public static readonly DependencyProperty ImageDisabledProperty =
            DependencyProperty.Register("ImageDisabled", typeof(ImageSource), typeof(ImageStateButton), new PropertyMetadata(null));


        /// <summary>
        /// 是否应用默认的状态特效
        /// </summary>
        [Category("多状态")]
        [Description("是否为按钮的状态自动应用预设的特效（按下时高亮，禁用时显示灰度。）")]
        public bool ApplyStateEffect
        {
            get { return (bool)GetValue(ApplyStateEffectProperty); }
            set { SetValue(ApplyStateEffectProperty, value); }
        }

        public static readonly DependencyProperty ApplyStateEffectProperty =
            DependencyProperty.Register("ApplyStateEffect", typeof(bool), typeof(ImageStateButton), new PropertyMetadata(true));

        /// <summary>
        /// 是否应用默认的MouseOver效果
        /// </summary>
        public bool ApplyMouseOverEffect
        {
            get { return (bool)GetValue(ApplyMouseOverEffectProperty); }
            set { SetValue(ApplyMouseOverEffectProperty, value); }
        }

        public static readonly DependencyProperty ApplyMouseOverEffectProperty =
            DependencyProperty.Register("ApplyMouseOverEffect", typeof(bool), typeof(ImageStateButton), new PropertyMetadata(true));
        /// <summary>
        /// 是否应用默认的按钮禁用时的效果
        /// </summary>
        public bool ApplyDisabledEffect
        {
            get { return (bool)GetValue(ApplyDisabledEffectProperty); }
            set { SetValue(ApplyDisabledEffectProperty, value); }
        }

        public static readonly DependencyProperty ApplyDisabledEffectProperty =
            DependencyProperty.Register("ApplyDisabledEffect", typeof(bool), typeof(ImageStateButton), new PropertyMetadata(true));


        /// <summary>
        /// 是否应用默认的按钮按下效果
        /// </summary>
        public bool ApplyPressedEffect
        {
            get { return (bool)GetValue(ApplyPressedEffectProperty); }
            set { SetValue(ApplyPressedEffectProperty, value); }
        }

        public static readonly DependencyProperty ApplyPressedEffectProperty =
            DependencyProperty.Register("ApplyPressedEffect", typeof(bool), typeof(ImageStateButton), new PropertyMetadata(true));



        /// <summary>
        /// 图片拉伸方式
        /// </summary>
        [Category("多状态")]
        [Description("图片的拉伸方式")]
        public Stretch ImageStretch
        {
            get { return (Stretch)GetValue(ImageStretchProperty); }
            set { SetValue(ImageStretchProperty, value); }
        }

        public static readonly DependencyProperty ImageStretchProperty =
            DependencyProperty.Register("ImageStretch", typeof(Stretch), typeof(ImageStateButton), new PropertyMetadata(Stretch.None));




        /// <summary>
        /// 边框的圆角半径
        /// </summary>
        [Category("多状态")]
        [Description("边框圆角半径")]
        public CornerRadius CornerRadius
        {
            get { return (CornerRadius)GetValue(CornerRadiusProperty); }
            set { SetValue(CornerRadiusProperty, value); }
        }

        public static readonly DependencyProperty CornerRadiusProperty =
            DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(ImageStateButton), new PropertyMetadata(new CornerRadius(0d)));


    }
}
